<script type="text/javascript">
	function SlideCtrl($scope, CtrlUtil, $http, $element, $injector, $q, modalService, UploadService) {
		var ctrl = this;
		ctrl.pageNumber = 0;
		// 查詢
		this.dialogPop = function (content, edit, slide, option) {
			var q = $q.defer();
			var method = 'confirm';
			modalService[method]({
				title: edit ? '编辑' : '添加',
				content: content,
				slide: slide
			}, option).then(function (r) {
				q.resolve(slide);
			})
			return q.promise;
		};
		// 添加幻灯
		this.dialogAdd = function () {
			var content = $element.find('.tpl>form').clone();
			var slide = {
			};
			var btn = content.find('[file]');
			ctrl.dialogPop(content, false, slide, {
				backdrop: false
			}).then(function (r) {
				ctrl.data.getData().push(slide);
				ctrl.data.doSave()
			});
		};
		// 预览
		this.edit = function (slide) {
			var content = $element.find('.tpl>form').clone();
			ctrl.dialogPop(content, true, slide).then(function () {
				ctrl.data.flushChange()
			});
		};
		// 删除
		this.remove = function (item) {
			var items = [];
			if (item) {
				items.push(item);
			} else {
				var checked = ctrl.data.getData().getChecked();
				if (checked.length == 0) {
					return;
				}
				angular.forEach(checked, function (v) {
					items.push(v);
				});
			}
			return modalService.confirm({
				title: '删除!(警告，培训类别的删除将会导致相关所有数据的删除，请谨慎操作)',
				titleCls: 'text-danger',
				content: '确定要<label class="text-danger">删除</label>选中的' + items.length + '条数据吗?'
			}).then(function (r) {
				ctrl.data.getData().removeChecked()
				ctrl.data.flushChange()
			});
		};
		this.checkAll = function (b) {
			CtrlUtil.checkAll(ctrl, b)
		};
	}

</script>
<!-- Search area -->
<div ng-controller="SlideCtrl as ctrl">
	<!-- Search area -->
	<div class="panel panel-cys">
		<div class="panel-heading">
			<h3 class="panel-title">
				<span class="glyphicon glyphicon-search"></span> 培训类别管理
			</h3>
		</div>
	</div>
	<!-- Search area END -->

	<!-- operation area -->
	<button type="button" class="btn btn-cys btn-sm" ng-click="ctrl.dialogAdd()">
		<span class="glyphicon glyphicon-plus"></span>
		新增
	</button>
	<button type="button" class="btn btn-danger btn-sm" ng-click="ctrl.remove()">
		<span class="glyphicon glyphicon-minus"></span>
		删除
	</button>
	<div class="ny-top-r pull-right">
		<pager bind-ctrl="ctrl.data"></pager>
	</div>
	<!-- operation area END -->

	<data bind-ctrl="ctrl.data" entity="TrainType" auto-load="true" show-toast="true"></data>
	<!-- data grid area -->
	<div style="padding-top: 10px;">
		<table class="table table-bordered table-hover table-striped">
			<tr>
				<th>
					<input ng-click="ctrl.checked=!ctrl.checked;ctrl.data.getData().checkAll(ctrl.checked)" type="checkbox" />
				</th>
				<th>名称</th>
				<th>开放学生申请</th>
				<th>开放老师申请</th>
				<th>操作</th>
			</tr>
			<tr ng-repeat="item in ctrl.data.getData()">
				<td><input ng-model="item.$$checked" type="checkbox" /></td>
				<td>{{item.name}}</td>
				<td>{{item.forStudent|toBool}}</td>
				<td>{{item.forTeacher|toBool}}</td>
				<td><a href="javascript:;" ng-click="ctrl.edit(item)">编辑</a></td>
			</tr>
		</table>
		<p>
			共有记录：
			<span>{{ctrl.data.getPage().total}}</span> 条
		</p>
	</div>
	<!-- data grid area END -->

	<!-- 幻灯片新增、编辑弹出框 -->
	<div ng-non-bindable class="tpl hidden">
		<form>
			<div class="form-group">
				<label>培训名称</label>
				<input type="text" class="form-control" ng-model="slide.name" required="required">
			</div>
			<div class="checkbox">
				<label><input type="checkbox" ng-model="slide.forStudent">开放学生申请</label>
			</div>
			<div class="checkbox">
				<label><input type="checkbox" ng-model="slide.forTeacher">开放老师申请</label>
			</div>
		</form>
	</div>
	<!-- 幻灯片新增、编辑弹出框 END -->

	<!-- 幻灯片预览弹出框 -->
	<div ng-non-bindable class="tpl2 hidden">
		<div class="text-center">
			<img ng-src="{{slide.imageUrl}}" class="img-thumbnail">
		</div>
	</div>
	<!-- 幻灯片预览弹出框 END -->
</div>